package com.diandireader.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.diandireader.activity.R;

import android.content.Context;
import android.view.View;
import android.widget.GridView;
import android.widget.SimpleAdapter;

/**
 * 阅读器View产生器，用来产生某些通用的View
 * @author mayh
 *
 */
public class ViewFactory {

	//创建浏览模式下的菜单
	public static View getReadOptionMenu(Context context){
		//标题
		String[] optionTitle = {"自动翻页","添加书签","跳转","字体","载入书签","切换模式","编辑文本","更多"}; 
		//图片资源
		int[] optionImage = {R.drawable.menu_page_scroll_normal,R.drawable.menu_bookmark,R.drawable.menu_pagefind,R.drawable.menu_font
				,R.drawable.bookmark_load,R.drawable.menu_nightmode,R.drawable.menu_edit,R.drawable.menu_more};
		//获得view
		View view = View.inflate(context, R.layout.reader_option, null);
		//获得显示的GridView
		GridView gridView = (GridView)view.findViewById(R.id.reader_option_grid);
		//创建SimpleAdapter
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		for(int i=0;i<optionTitle.length;i++){
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("text", optionTitle[i]);
			map.put("image", optionImage[i]);
			list.add(map);
		}
		SimpleAdapter adapter = new SimpleAdapter(context, list, R.layout.reader_option_item, new String[]{"text","image"},
							new int[]{R.id.reader_option_item_text,R.id.reader_option_item_image});
		gridView.setAdapter(adapter);
		
		return view;
	}

}
